class Solution {
    public int divide(int dividend, int divisor) {
        //特殊情况，除法溢出
        if (dividend == Integer.MIN_VALUE && divisor == -1){
            return Integer.MAX_VALUE;
        }
        //判断负的情况
        boolean isNegative = (dividend > 0 && divisor < 0 || (dividend < 0 && divisor > 0));
        int re = 0;
        long a = Math.abs((long)dividend);
        long b = Math.abs((long)divisor);
        //移位法
        int n = 31;
        while(a >= b){
            while( a < b << n){
                n--;
            }
            a -= b << n;
            re += 1 << n;
        }
        return isNegative ? -re :re;
    }
}